000100******************************************************************
000200*PROGRAM : Add an instructor to the ISAM file                    *
000300*AUTHOR  : H. James Vo                                           *
000400******************************************************************
000500 IDENTIFICATION DIVISION.
000600 PROGRAM-ID. INST-A.
      *-----------------------------------------------------------------
000700 ENVIRONMENT DIVISION.
000800     SELECT IOFILE       ASSIGN TO "INSTMST.DAT"
000900                         ORGANIZATION  IS INDEXED
001000                         ACCESS        IS RANDOM
001100                         RECORD KEY    IS OUT-INST-ID
                               ALTERNATE KEY IS OUT-INST-NAME
                                             WITH DUPLICATES
001200                         FILE STATUS   IS WS-STAT.

001300*-----------------------------------------------------------------
001400 DATA DIVISION.
001500 FILE SECTION.
001600 FD  IOFILE.
001700 01  OUT-REC.
001800     03  OUT-INST-ID     PIC 9(3).
001900     03  OUT-INST-NAME   PIC X(20).
002100     03  OUT-INST-A      PIC X.
002200
002300 WORKING-STORAGE SECTION.
002400 01  WS-STAT             PIC XX.
002500 01  WS-EOF              PIC X VALUE 'N'.
002600 01  WS-INST-ID          PIC 9(3).
002700 01  WS-INST-NAME        PIC X(30).
002900 01  WS-INST-A           PIC X.
003000 01  WS-DATE.
003100     03  WS-YEAR         PIC 99.
003200     03  WS-MONTH        PIC 99.
003300     03  WS-DAY          PIC 99.
003400 01  WS-ERR              PIC X VALUE 'N'.
003500 01  WS-CONT             PIC X VALUE SPACES.
003600 01  WS-ADD              PIC X VALUE 'N'.

003700 SCREEN SECTION.
003800 01  INPUT-SCRN.
003900         05  BLANK SCREEN.
004000         05  LINE 1  COL 01  VALUE "ADD INSTRUCTOR".
004100         05          COL 73  PIC 9(2) FROM WS-MONTH.
004200         05          COL 75  VALUE "/".
004300         05          COL 76  PIC 9(2) FROM WS-DAY.
004400         05          COL 78  VALUE "/".
004500         05          COL 79  PIC 9(2) FROM WS-YEAR.
004600         05  LINE 2  COL 35  VALUE "ADD INSTRUCTOR".
004700         05  INPUT-INST-ID-SCRN.
004800             10  LINE 4  COL 20  VALUE "INSTRUCTOR ID".
004900             10          COL 40  PIC 9(3) TO WS-INST-ID.
005900         05  LINE 5  COL 20  VALUE "(ENTER 000 AS ID TO EXIT)".

005000         05  INPUT-INST-NAME-SCRN.
005100             10  LINE 7  COL 20  VALUE "INSTRUCTOR NAME".
005200             10          COL 40  PIC X(20) TO WS-INST-NAME.
               05  LINE 8  COL 20  VALUE "EX: H.  Keller (TWO SPACES AFT
      -                                  "ER THE FIRST INITIAL)".
005600         05  INPUT-INST-A-SCRN.
005700             10  LINE 10 COL 20  VALUE "ACTIVATE (Y/N)?".
005800             10          COL 40  PIC X TO WS-INST-A AUTO.
006000 01  ERROR-SCRN.
006100     03  BLANK SCREEN.
006200     03  LINE 12 COL 32 VALUE "ERROR ADDING RECORD".
006300     03  LINE 14 COL 32 VALUE "FILE STATUS:".
006400     03          COL 46 PIC XX FROM WS-STAT.
006500     03  LINE 15 COL 32 VALUE "RECORD KEY:".
006600     03          COL 46 PIC X(8) FROM OUT-INST-ID.
006700     03  LINE 16 COL 32 VALUE "CONTINUE(Y/N)?".
006800     03          COL 47 PIC X TO WS-CONT AUTO.
006900
009100 01  ADD-REC-SCRN.
009200     03  BLANK SCREEN.
009300     03  LINE 4  COL 20 VALUE "INSTRUCTOR ID".
009400     03          COL 40 PIC X(3) FROM WS-INST-ID.
009500     03  LINE 5  COL 20 VALUE "INSTRUCTOR NAME".
009600     03          COL 40 PIC X(20) FROM WS-INST-NAME.
010100     03  LINE 8  COL 20 VALUE "ACTIVATE (Y/N)?".
010200     03          COL 40 PIC X FROM WS-INST-A.
010300     03  LINE 9  COL 32 VALUE "DO YOU WANT TO ADD RECORD(Y/N)?".
010400     03          COL 65 PIC X TO WS-ADD AUTO.

       01  SUCCESS-SCRN.
007100     03  BLANK SCREEN.
007200     03  LINE 12 COL 32 VALUE "RECORD ADDED".
007300     03  LINE 13 COL 32 VALUE "RECORD INFORMATION:".
007400     03  LINE 14 COL 32 VALUE "INSTRUCTOR ID".
007500     03          COL 48 PIC X(8) FROM OUT-INST-ID.
007600     03  LINE 15 COL 32 VALUE "INSTRUCTOR NAME".
007700     03          COL 48 PIC X(30) FROM OUT-INST-NAME.
008000     03  LINE 16 COL 32 VALUE "ACTIVATE?".
008100     03          COL 48 PIC X FROM OUT-INST-A.
008200     03  LINE 17 COL 32 VALUE "CONTINUE (Y/N)?".
008300     03          COL 49 PIC X TO WS-CONT AUTO.
008400
008500*-----------------------------------------------------------------
008600 PROCEDURE DIVISION.
008700 100-MAIN.
008800     ACCEPT WS-DATE FROM DATE
008900     OPEN I-O IOFILE.
           PERFORM 300-PREOP
009900     PERFORM 200-LOOP
013200     CLOSE IOFILE
013300     EXIT PROGRAM.
010000
       200-LOOP.
           PERFORM UNTIL WS-INST-ID = ZEROS OR WS-CONT = 'N'
               ACCEPT  INPUT-INST-NAME-SCRN
010200         ACCEPT  INPUT-INST-A-SCRN
010300
010400         MOVE WS-INST-ID     TO OUT-INST-ID
010500         MOVE WS-INST-NAME   TO OUT-INST-NAME
010700         MOVE WS-INST-A      TO OUT-INST-A
010800
010900         MOVE 'N' TO WS-ERR

               DISPLAY ADD-REC-SCRN
               ACCEPT  ADD-REC-SCRN
               IF      WS-ADD = 'Y'
011100             WRITE OUT-REC
011200                 INVALID KEY MOVE 'Y' TO WS-ERR
011300             END-WRITE
011500             IF WS-ERR = 'Y'
011600                 DISPLAY ERROR-SCRN
011700                 ACCEPT  ERROR-SCRN
                       IF      WS-CONT = 'Y'
                           PERFORM 300-PREOP
                           PERFORM 200-LOOP
                       END-IF
012100             ELSE
011900                 DISPLAY SUCCESS-SCRN
012000                 ACCEPT  SUCCESS-SCRN
                       IF      WS-CONT = 'Y'
                           PERFORM 300-PREOP
                           PERFORM 200-LOOP
                       END-IF
                   END-IF
               ELSE IF WS-ADD = 'N'
                   PERFORM 300-PREOP
                   PERFORM 200-LOOP
               END-IF
           END-PERFORM.

011400 300-PREOP.
009100     MOVE ZEROS  TO WS-INST-ID
009200     MOVE SPACES TO WS-INST-NAME
009400     MOVE SPACES TO WS-INST-A
009500     MOVE SPACES TO WS-CONT
009700     DISPLAY INPUT-SCRN
009800     ACCEPT  INPUT-INST-ID-SCRN.

012200
013100
